home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / NTUMIN10.ARJ / POWER.C < prev    next >
Text File  |  1992-03-12  |  2KB  |  54 lines

  1. /******************************************************************************
  2.  *
  3.  *    Program Name : POWER.C
  4.  *
  5.  *    Written By : Eng-Huat Ong and Kian-Mong Low.
  6.  *
  7.  *    This program computes the value 2 raise to the power of n, where
  8.  *    n is the number of variables.
  9.  *
  10.  *    Returns  2 raise to power n
  11.  *
  12.  * --------------------------------------------------------------------------
  13.  *    Copyright (c) 1992. All Rights Reserved. Nanyang Technological
  14.  *    University.
  15.  *
  16.  *    You are free to use, copy and distribute this software and its
  17.  *    documentation providing that:
  18.  *
  19.  *        NO FEE IS CHARGED FOR USE, COPYING OR DISTRIBUTION.
  20.  *
  21.  *        IT IS NOT MODIFIED IN ANY WAY.
  22.  *
  23.  *        THE COPYRIGHT NOTICE APPEAR IN ALL COPIES.
  24.  *
  25.  *    This program is provided "AS IS" without any warranty, expressed or
  26.  *    implied, including but not limited to fitness for any particular
  27.  *    purpose.
  28.  *
  29.  *    If you find NTUMIN fast, easy, and useful, a note or comment would be
  30.  *    appreciated. Please send to:
  31.  *
  32.  *        Boon-Tiong Tan or Othman Bin Ahmad
  33.  *        School of EEE
  34.  *        Nanyang Technological University
  35.  *        Nanyang Avenue
  36.  *        Singapore 2263
  37.  *        Republic of Singapore
  38.  *
  39.  ******************************************************************************/
  40.  
  41. unsigned long  topow(n)
  42.  
  43. unsigned char n;                          /* exponent */
  44.  
  45. {
  46.    unsigned long  x=1, p;                 /* counters */
  47.  
  48.    for ( p=1; p<=n; p++)                  /* do n times */
  49.       x = x*2;
  50.  
  51.    return (x);                            /* return 2 raise to power n */
  52. }
  53.  
  54.